﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FineSoft.Models
{
	public class ArrayObject : Object
	{
		public override string ConfigsString
		{
			get
			{
				return "[" + string.Join(",", this.Items.Select(o => o.ConfigsString).ToArray()) + "]";
			}
		}

		private System.Collections.Generic.List<Object> _Items;
		public System.Collections.Generic.List<Object> Items
		{
			get
			{
				if (this._Items == null)
					this._Items = new List<Object>();
				return this._Items;
			}
		}

		public ArrayObject()
		{
		}

		#region ISerializable 成员

		public ArrayObject(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
			: base(info, context)
		{
			int count = info.GetInt32("Count");
			for (int i = 0; i < count; i++)
				this.Items.Add((Object)info.GetValue("Value_" + i, System.Type.GetType(info.GetString("Type_" + i))));
		}

		public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
		{
			info.AddValue("Count", this.Items.Count);
			for (int i = 0; i < this.Items.Count; i++)
			{
				Object item = this.Items[i];
				info.AddValue("Type_" + i, item.GetType().GetName());
				info.AddValue("Value_" + i, item);
			}
		}

		#endregion
	}
}